/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-12-28 11:45:36
 * @LastEditors: aggfb 714740235@qq.com
 * @LastEditTime: 2025-02-26 22:03:11
 * @FilePath: \wire_receiver_collect_box\communication\com_lora.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __COM_LORA_H
#define __COM_LORA_H

#include <stdint.h>

#define SLAVE_DRV_NUMBER 2U /* 从机设备个数 */
#define DRIVEN_PLATE_NUMBER 32U /* 从动盘设备个数 */

#define CAN_DRIVER_ID_TOP 15

#pragma pack(1)
/* 按键设备 */
struct key_drv
{
    uint8_t start_sta; /* 开关状态 */
    uint8_t slow_sta;
    uint8_t stop_sta; 

    uint8_t start_ctrl; /* 控制状态 */
    uint8_t slow_ctrl;
    uint8_t stop_ctrl;
};

/* 收线设备 */
struct calculate_line_drv
{
	uint8_t addr;   /* 本机lora地址 */
    int64_t plus;   /* 脉冲数据 */
};

/* 从动盘设备 */
struct slave_drv_info
{
    uint8_t addr;    /* 从动盘 地址 */
    int16_t rpm;     /* 转速 +-代表方向 */
};
struct box_drv_info
{
    uint8_t addr;                                      /* 从动盘总机 lora地址 */
    struct slave_drv_info drv_info[CAN_DRIVER_ID_TOP]; /* 从动盘 地址和转速 */
    uint32_t box_bits;                                 /* 从动盘状态 */
};

/* 显示屏设备 */
struct monitor_drv
{
    uint8_t flag_update;
};

union addr_u{
    uint8_t bits;
    struct _addr
    {
        uint8_t target_addr:4; /* 目标地址 */
        uint8_t source_addr:4; /* 源地址 */
    }_bit;
};

struct master_lora_drv
{
    struct key_drv key[SLAVE_DRV_NUMBER];                       // 按键设备
    struct calculate_line_drv calculate_line[SLAVE_DRV_NUMBER]; // 计线设备
    struct box_drv_info driven_plate[SLAVE_DRV_NUMBER];         // 从动盘设备
    struct monitor_drv monitor;               // 显示屏

    uint8_t flag_on_use;

    double drv1_len_m;
    double drv2_len_m;
};


#pragma pack()

extern struct master_lora_drv master_lora;

extern int16_t com_lora_send_cmd(uint8_t slave_id, uint8_t data);
extern int16_t com_lora_recv_handle(void);
extern void lora_receive_analysis(uint8_t byte);
extern void com_lora_tx_hanlder(void);

#endif
